<script type="text/javascript" language="javascript">
    (function($) {
        /*whatever jQuery stuff*/
        $(function(){
            jQuery.validator.addMethod("detail_required", function(value, element, param) {
                var returnVal = true;				
				if(CKEDITOR.instances.news_detail.getData()==''){
					returnVal = false;
				}
				return returnVal;
           	}, jQuery.validator.messages.detail_required);
											
            $("#Form").validate({
				ignore: "",
                rules: {
					news_type_id: "required",
					news_subject: "required",
					news_brief: "required",
					news_detail: {
						detail_required:true
					},
					news_tag: "required"
                },
                showErrors: function(errorMap, errorList){
                    var messages='';
                    for (var i = 0; i < errorList.length; i++) {					
                        messages += '- '+errorList[i].message+'\n';
                    }
                    if(messages) alert("<?php echo lang('requirement');?>: \n"+"¯¯¯¯¯¯¯¯¯¯ \n"+ messages);
                    //this.defaultShowErrors();
                } ,
                submitHandler: function(e){
					$('.ajax-loading',e).css('visibility','visible');
					if(queueSize > 0){
						$('#file_upload').uploadifyUpload();
					} else { success_file = true; }				
					var interval = setInterval(function() {
					    if (success_file) {
					        clearInterval(interval);
							//Send Form
					        document.forms["Form"].submit();
					    }
					}, 100);
                },
                onfocusout: false,
                onkeyup: false,
				onclick: false,					
                messages: {
					news_type_id: "<?php echo lang('news_type');?>",
					news_subject: "<?php echo lang('news_subject');?>",
					news_brief: "<?php echo lang('news_brief');?>",
					news_detail: {
						detail_required: "<?php echo lang('news_detail');?>"
					},					
					news_tag: "<?php echo lang('news_tag');?>"	
                }
            });	
			
            /*Images Upload*/
            var queueSize = 0;		
            var imgname= new Array();
			var success_file = false;					
            $('#file_upload').uploadify({
                'uploader'  : '<?php echo base_url();?>uploadify.swf',				
                'script'    : '<?php echo base_url();?>uploadify.php',
                'cancelImg' : '<?php echo js_asset_url("uploadify/cancel.png"); ?>',
                'folder'    : "<?php echo substr($this->temp_folder,0,-1);?>",
                'fileExt'   : '*.jpg;*.JPG;*.gif;*.GIF;*.png;*.PNG',
                'fileDesc'  : 'All Files',
				'scriptAccess' : 'always',			
                'auto'      : false,
                'multi'     : true,
                'onComplete' : function(event, ID, fileObj, response, data){
                    imgname.push(response);
                },
                'onAllComplete' : function(event,data) {
					$('<input>').attr({
					    type: 'hidden',
					    id: 'uploadify_store',
					    name: 'uploadify_store',
						value: imgname
					}).appendTo('Form');
					//document.forms["Form"].submit();					
					success_file=true;
                },
                'onSelectOnce' : function (event,data) {
                    queueSize = data.fileCount;
                },
                'onCancel' : function (event,ID,fileObj,data) {
                    queueSize = data.fileCount;
                }						
            });			
			//DateTime Picker
			$('.datetime').datetimepicker({
				dateFormat:'dd/mm/yy',
				timeFormat:'hh:mm',
				separator:' ',
			    changeMonth : true,
			    changeYear : true,
			    yearRange: '-100y:c+nn',
			    maxDate: '-1d',
				showHour: true,		
				showMinute: true,
				showTime: true		
			});
			//ColorBox Iframe
			$('.search_tools').colorbox({iframe:true, innerWidth:300, innerHeight:600, right:0, opacity:0.4});		
        });
    })(jQuery);
		/*Show Search*/
		var news_relate_on_search='';
		function showSearch(e)
		{
			$(e).parent().find('.search_tools2').remove();
			$(e).parent().find('input').val('');
			switch(e.value){
				case 'Album':
					$(e).parent().append('<a href="<?php echo base_url()."news/content_management/search_album";?>" class="tools magnify search_tools2"></a>');
				break;
				case 'Movie':
					$(e).parent().append('<a href="<?php echo base_url()."news/content_management/search_movie";?>" class="tools magnify search_tools2"></a>');
				break;
				case 'Song':
					$(e).parent().append('<a href="<?php echo base_url()."news/content_management/search_song";?>" class="tools magnify search_tools2"></a>');
				break;
				case 'Video':
					$(e).parent().append('<a href="<?php echo base_url()."news/content_management/search_video";?>" class="tools magnify search_tools2"></a>');
				break;
				case 'Gallery':
					$(e).parent().append('<a href="<?php echo base_url()."news/content_management/search_gallery";?>" class="tools magnify search_tools2"></a>');
				break;
				case 'Fashion':
					$(e).parent().append('<a href="<?php echo base_url()."news/content_management/search_fashion";?>" class="tools magnify search_tools2"></a>');
				break;																				
			}
			$('.search_tools2').colorbox({
				onLoad:function(){ news_relate_on_search = $(this).parent(); },
				onClosed:function(){ news_relate_on_search = "";},
				iframe:true, 
				innerWidth:300, 
				innerHeight:600, 
				right:0, 
				opacity:0.4
			});
		}
		/*Add/Remove List*/
		function addRemoveList(unique,id,name)
		{
			if(news_relate_on_search != ""){
				news_relate_on_search.find('input[name="news_relate_id[]"]').val(''+id+'');	
			} else {
				if(id == undefined && name == undefined){ //remove List
					var parentElement = $(unique).closest('ul');
					$(unique).parent().remove();
					if($('li:not(:hidden)',parentElement).length < 1){
						parentElement.find('.first').show();
					}	
				} else { //add List
					var parentElement = $('#'+unique).closest('ul');
					parentElement.find('.first').hide();
					if($('input[value="'+id+'"]',parentElement).length == 0){
						parentElement.prepend('<li><input type="checkbox" name="default_'+unique+'[]" checked="checked"/>&nbsp;'+id+' - '+name+' <a href="javascript:void(0)" class="tools minus" onclick="javascript:addRemoveList(this);"></a><input type="hidden" name="'+unique+'[]" value="'+id+'" \/><\/li>');
					}		
				}				
			}
		}	
</script>
<div class="wrap">
 	<div id="icon-index" class="icon32"><br /></div><h2><?php echo ucwords(str_replace('_',' ',$this->uri->segment(1)));?> &raquo; <?php echo ucwords(str_replace('_',' ',$this->uri->segment(2)));?> &raquo; <?php echo lang($this->uri->segment(3));?></h2>
</div>
<div id="wpbody-content">
    <div class="metabox-holder" id="dashboard-widgets">
		<div class="tablenav top">
			<div class="alignleft"><input type="button" value="<?php echo lang('button_back');?>" class="button-primary" onclick="javascript:history.go(-1);"/></div>
		</div>	
            <div class="inside">			
				<form id="Form" method="post" action="" name="Form">
					<table border="0" cellspacing="0" cellpadding="0" class="form-table">
						<tbody>	
						<tr>
							<th scope="row"><?php echo lang('is_publish');?></th>
							<td>
								<input type="radio" name="is_publish" value="1" checked="checked"/> <?php echo lang('yes');?>
								<input type="radio" name="is_publish" value="0" /> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('news_publish_date');?></th>
							<td><input type="text" name="news_publish_date" id="news_publish_date" class="medium-text datetime" value="<?php echo date('d/m/Y H:i');?>" readonly="readonly"/></td>
						</tr>		
						<tr>
							<th scope="row"><?php echo lang('news_type');?></th>
							<td>
								<select id="news_type_id" name="news_type_id" class="medium-text" onchange="javacript:if($('.news_type_id_'+this.value+'').length > 0){$('tr[class*=\'news_type_id_\']').hide();$('.news_type_id_'+this.value+'').show()} else {$('tr[class*=\'news_type_id_\']').hide();}">
									<option value=""><?php echo lang('select_option');?></option>
									<?php foreach($dataNewsType as $value):?>
										<option value="<?php echo $value->news_type_id;?>"><?php echo $value->news_type_name;?></option>
									<?php endforeach;?>
								</select>							
							</td>
						</tr>
						<tr class="news_type_id_5" style="display:none;">
							<th scope="row">
								<?php echo lang('news_review_hilight');?>
							</th>
							<td>
								<input type="radio" name="is_review_hilight" value="1" /> <?php echo lang('yes');?>
								<input type="radio" name="is_review_hilight" value="0" checked="checked"/> <?php echo lang('no');?>
							</td>
						</tr>						
						<tr>
							<th scope="row"><?php echo lang('news_main_hilight');?></th>
							<td>
								<input type="radio" name="is_main_hilight" value="1" /> <?php echo lang('yes');?>
								<input type="radio" name="is_main_hilight" value="0" checked="checked"/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('news_type_hilight');?></th>
							<td>
								<input type="radio" name="is_type_hilight" value="1" /> <?php echo lang('yes');?>
								<input type="radio" name="is_type_hilight" value="0" checked="checked"/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('author_by');?></th>
							<td>
								<select name="author_by" id="author_by">
									<option selected="selected">YOU2PLAY</option>
									<option>หัตถาครองพิภพ</option>
									<option>นักเลงเพลงสยาม</option>
								</select>
							</td>
						</tr>												
						<tr>
							<th scope="row"><?php echo lang('news_subject');?></th>
							<td><input type="text" name="news_subject" id="news_subject" class="regular-text" /></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('news_brief');?></th>
							<td>
								<textarea name="news_brief" id="news_brief" rows="5" class="regular-text"></textarea>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('news_detail');?></th>
							<td><?php echo display_ckeditor('news_detail','',array('toolbar' => 'Medium','skin' => 'v2','width' => '550px','height' => '200px'),false); ?></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('news_tag');?></th>
							<td><input type="text" name="news_tag" id="news_tag" class="regular-text" /></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('artist_relate');?> <a href="<?php echo base_url().'news/content_management/search_artist';?>" class="tools plus search_tools"></a></th>
							<td>
								<ul id="artist_id" class="listItems">
									<li class="first"><?php echo lang('no_artist_relate');?></li>
								</ul>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('news_relate');?></th>
							<td>
								<a href="javascript:void(0);" class="tools minus" onclick="javascript:removeclone(this,'div');"></a>
								<a href="javascript:void(0);" class="tools plus" onclick="javascript:addclone(this,'div',null,'.search_tools2');"></a>
								<div style="padding:3px 0;">
									<select name="news_relate_module[]" onchange="javascript:showSearch(this);">
										<option value=""><?php echo lang('select_option');?></option>
										<option value="Album">Album ID:</option>								
										<option value="Movie">Movie ID:</option>
										<option value="Song">Song ID:</option>
										<option value="Video">Video ID:</option>									
										<option value="Gallery">Gallery ID:</option>									
										<option value="Fashion">Fashion ID:</option>									
									</select>
									<input type="text" name="news_relate_id[]" class="small-text" readonly="readonly"/>
								</div>
							</td>
						</tr>											
						<tr>
							<th scope="row"><?php echo lang('news_image');?></th>
							<td><input type="file" name="file_upload" id="file_upload"/></td>
						</tr>																						
						<tr>
							<th scope="row">&nbsp;</th>
							<td><p class="submit"><input type="submit" value="<?php echo lang('button_add');?>" class="button-primary" />&nbsp;<img alt="" class="ajax-loading" src="<?php echo css_asset_url('images/wpspin_light.gif'); ?>" /></p></td>
						</tr>								
						</tbody>
					</table>
					<div class="tablenav bottom"></div>
				</form>
            </div><!-- wpbody inside -->
    </div><!-- wpcontent -->
</div><!-- wpbody-content -->